home *** CD-ROM | disk | FTP | other *** search
- /* getw.c, from p. 444 of Turbo C Bible */
- #include <stdio.h>
- main()
- {
- int word1;
- FILE *infile;
- char filename[81];
- printf("Enter name of a file to read from: ");
- gets(filename);
- /* Open the file for reading */
- if ((infile = fopen(filename, "rb")) == NULL)
- {
- printf("fopen failed.\n");
- exit(0);
- }
- /* Get first word from file */
- if ((word1 = getw(infile)) == EOF)
- {
- /* Check if tere was a real error */
- if (feof(infile) != 0)
- {
- printf("File: %s at EOF\n", filename);
- exit(0);
- }
- if (ferror(infile) != 0)
- {
- printf("File: %s Read error\n", filename);
- exit(0);
- }
- }
- /* Print out the first word in hexa- */
- /* decimal */
- printf("The first word in file %s is: %X\n", filename, word1);
- printf("Use 'TYPE %s' to confirm this.\n", filename);
- }